<script>
	import {
		getChainInfo,
		getApp_config
	} from './http/api.js'
	import getAppVersion from '@/js_sdk/common/updataApp.js'
	export default {
		onLaunch: async function() {
			this.getChain()
		},
		onShow: async function() {
			this.upApp()
		},
		onHide: function() {},
		methods: {
			upApp() {
				getApp_config().then(res => {
					if(res.code==200){
						getAppVersion(res.data.version,res.data.url)
						if(res.data.status=="0"){
							this.$store.commit('setAppstatus', 0);
						}
					}
				})
			},
			async getChain() {
				const res = await getChainInfo();
				if (res.code == 200) {
					let list = res.data?.map(chain => ({
						chainId: chain.chainId,
						defultRPC: chain.defultRPC
					}));
					let allchains = uni.getStorageSync('allchains') || {};
					let rpclist = uni.getStorageSync('rpclist') || [];
					if (!allchains || JSON.stringify(allchains) != JSON.stringify(res.data)) {
						this.$store.commit('setAllchains', res.data);
					}
					if (!rpclist || list?.length != rpclist?.length) {
						// 找出 list 中不在 rpclist 中的项
						let newChains = list.filter(chain => !rpclist.some(rpc => rpc.chainId === chain.chainId));
						if (newChains.length > 0) {
							rpclist = [...rpclist, ...newChains];
						}
						uni.setStorageSync('rpclist', rpclist);
					}
				}
				this.$updateWalletInfo()
			}
		}
	}
</script>

<style lang="scss">
	// uni-app,
	// uni-page,
	// uni-page-wrapper,
	// uni-page-body {
	// 	height: 100%;
	// }
	.uni-dialog-title {
		.uni-popup__info {
			color: #3D3D3D;

			.uni-dialog-title-text {
				font-size: 36upx;
				font-weight: 400;
			}

		}
	}


	/*每个页面公共css */
</style>